package com.shoy.myapp.ui;


import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import com.shoy.myapp.R;

/**
 * 加载进度
 *
 * @author shoy
 * @created 2015/04/02
 */
public class DlgFrgProgress extends DialogFragment {
    private final static String CANCELABLE_ARG = "cancelable";

    public static DlgFrgProgress getInstance(boolean can) {
        Bundle args = new Bundle();
        args.putBoolean(CANCELABLE_ARG, can);
        DlgFrgProgress frag = new DlgFrgProgress();
        frag.setArguments(args);
        return frag;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final boolean cancelable = getArguments().getBoolean(CANCELABLE_ARG);
        Dialog dialog = new Dialog(getActivity(), R.style.Dialog);
        dialog.setContentView(R.layout.processbar);
        dialog.setCancelable(cancelable);
        return dialog;
    }

    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        if (isCancelable()) {
            if (getActivity() instanceof OnDismissListener) {
                ((OnDismissListener) getActivity()).onDismiss(dialog);
            }
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
    }
}
